package com.lengchangjing.StructuralPatterns.CompositePattern;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class Composite implements Component {
    private List<Component> components = new ArrayList<Component>();

    @Override
    public void Operaton(int depth) {
        System.out.println(StringUtils.repeat(' ',depth - 2) + "|");
        System.out.println(StringUtils.repeat(' ',depth - 2) + "--" + this.getClass().getSimpleName() + " Operation");
        for(Component component:components)
        {
            component.Operaton(depth + 2);
        }
    }

    @Override
    public void Add(Component component) {
        components.add(component);
    }

    @Override
    public void Remove(Component component) {
        components.remove(component);
    }

    @Override
    public Component GetChild(int i) {

        return components.get(i);
    }
}
